home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 351-375 / disk_371 / fractals / src / wilbm.c < prev   
C/C++ Source or Header  |  1992-05-06  |  2KB  |  102 lines

  1. /* _WriteILBMFile.c ranxerox 2.0 890521 900323 */
  2. #include <libraries/dosextens.h>
  3. #include <exec/types.h>
  4. #include <intuition/intuition.h>
  5. #define SAVE 0L
  6. #define NOSAVE 1L
  7. #define NOOPEN 2L
  8.  
  9. extern struct GfxBase *GfxBase;
  10.  
  11. static struct FileHandle *_W_fh,*Open();
  12. static long Write();
  13. static short DeleteFile();
  14. static void prepbuff(),Close();
  15. static short GetRGB4();
  16. static long flag;
  17. static void cWrite();
  18.  
  19. long WriteILBMFile(filename,scr)
  20. char filename[];
  21. struct Screen *scr;
  22. {
  23. unsigned long scrrowbytes,rr,pp;
  24. UBYTE colors;
  25. unsigned short vm;
  26. short index,red,green,blue,color;
  27. UBYTE *planepointer;
  28. long tmp;
  29.  
  30. flag=SAVE;
  31. vm=( (scr->ViewPort.Modes) & (HIRES|HAM|LACE|EXTRA_HALFBRITE) );
  32. colors=(1<<scr->BitMap.Depth);
  33. if(vm&HAM)colors=16;
  34. if(vm&EXTRA_HALFBRITE)colors=32;
  35.  
  36. if((_W_fh=Open(filename,MODE_NEWFILE))==NULL)flag=NOOPEN;
  37. cWrite((char *)"FORM",4L);
  38. tmp=(long)(3L*colors+(scr->Width)/8L*(scr->Height)*(scr->BitMap.Depth)+60L);
  39. cWrite((char *)&tmp,4L);
  40. cWrite((char *)"ILBMBMHD",8L);
  41. tmp=20L;
  42. cWrite((char *)&tmp,4L);
  43. cWrite((char *)&scr->Width,2L);
  44. cWrite((char *)&scr->Height,2L);
  45. tmp=0L;
  46. cWrite((char *)&tmp,4L);
  47. tmp=(long)scr->BitMap.Depth<<24;
  48. cWrite((char *)&tmp,2L);
  49. tmp=0L;
  50. cWrite((char *)&tmp,4L);
  51. tmp=(long)0xA0B<<16;
  52. cWrite((char *)&tmp,2L);
  53. cWrite((char *)&scr->Width,2L);
  54. cWrite((char *)&scr->Height,2L);
  55. cWrite((char *)"CAMG",4L);
  56. tmp=4L;
  57. cWrite((char *)&tmp,4L);
  58. tmp=(long)vm;
  59. cWrite((char *)&tmp,4L);
  60. cWrite((char *)"CMAP",4L);
  61. tmp=(long)colors*3;
  62. cWrite((char *)&tmp,4L);
  63. for(index=0;index<colors;index++)
  64. {
  65.  color=GetRGB4(scr->ViewPort.ColorMap,(long)index);
  66.  red=color>>8;color-=red<<8;
  67.  green=color>>4;color-=green<<4;
  68.  blue=color;
  69.  tmp=red*16;tmp<<=8;
  70.  tmp+=green*16;tmp<<=8;
  71.  tmp+=blue*16 ;tmp<<=8;
  72.  cWrite((char *)&tmp,3L);
  73. };
  74. cWrite((char *)"BODY",4L);
  75. tmp=(long)((scr->Width)/8L*(scr->Height)*(scr->BitMap.Depth));
  76. cWrite((char *)&tmp,4L);
  77. scrrowbytes=scr->Width/8;
  78. for(rr=0;rr<scr->Height;rr++)
  79. { for(pp=0;pp<scr->BitMap.Depth;pp++)
  80.   {
  81.   planepointer=scr->BitMap.Planes[pp] + (rr*scrrowbytes);
  82.   cWrite((char *)planepointer,(long)scrrowbytes);
  83.   };
  84. };
  85. if(_W_fh)Close(_W_fh);
  86. if(flag==NOSAVE)DeleteFile(filename);
  87. return(flag);
  88. }
  89.  
  90. void cWrite(pntr,len)
  91. char *pntr;
  92. long len;
  93. {
  94.   if(flag==SAVE)
  95.     {
  96.      if( Write(_W_fh,pntr,len) == -1L)flag=NOSAVE;
  97.     };
  98. }
  99.  
  100.  
  101.  
  102.